package com.dimaidt.girl.service.impl;

import com.dimaidt.girl.domain.Girl;
import com.dimaidt.girl.enums.ResultEnum;
import com.dimaidt.girl.exception.GirlException;
import com.dimaidt.girl.repository.GirlRepository;
import com.dimaidt.girl.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : Alex Hu
 * date : 2020/2/26 上午07:11
 * description :
 */
@Service
public class GirlServiceImpl implements GirlService {
    @Autowired
    GirlRepository girlRepository;


    @Override
    public List<Girl> getList() {
        return girlRepository.findAll();
    }

    @Override
    public List<Girl> findByAge(Integer age) {
        return girlRepository.findByAge(age);
    }

    @Override
    public void getAgeMsg(Integer id) throws Exception {
        Girl girl = girlRepository.findById(id).orElse(null);
        if (girl.equals(null)) {
            return;
        }
        Integer age = girl.getAge();
        if (age <= 10) {
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        } else if (age > 10 && age < 16) {
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);

        } else {
            throw new Exception("你还在上学么");//留个系统异常对比看结果
        }
    }
}
